import { login } from '@/api/user';

export default {
  namespaced: true,
  state: {
    token: null,
  },
  mutations: {
    saveToken(state, token) {
      state.token = token;
      console.log(state.token);
    },
    removeToken(state) {
      state.token = null;
    },
  },
  actions: {
    async login(context, user) {
      const res = await login(user);
      context.commit('saveToken', res.token);
    },
  },
};
